package com.ts.animal.controller;

import com.ts.animal.domain.ParturitionRecordDO;
import com.ts.animal.service.ParturitionRecordService;
import com.ts.common.utils.PageUtils;
import com.ts.common.utils.Query;
import com.ts.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 生产记录表
 *
 * @author bobby
 * @email bobby@126.com
 * @date 2022-09-02 16:22:28
 */

@Controller
@RequestMapping("/animal/parturitionRecord")
public class ParturitionRecordController {
    @Autowired
    private ParturitionRecordService parturitionRecordService;

    @GetMapping()
    @RequiresPermissions("animal:parturitionRecord:parturitionRecord")
    String ParturitionRecord() {
        return "animal/parturitionRecord/parturitionRecord";
    }

    @ResponseBody
    @RequestMapping("/list")
    @RequiresPermissions("animal:parturitionRecord:parturitionRecord")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ParturitionRecordDO> parturitionRecordList = parturitionRecordService.list(query);
        int total = parturitionRecordService.count(query);
        PageUtils pageUtils = new PageUtils(parturitionRecordList, total);

        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("animal:parturitionRecord:add")
    String add() {
        return "animal/parturitionRecord/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("animal:parturitionRecord:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        ParturitionRecordDO parturitionRecord = parturitionRecordService.get(id);
        model.addAttribute("parturitionRecord", parturitionRecord);
        return "animal/parturitionRecord/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("animal:parturitionRecord:add")
    public Result save(ParturitionRecordDO parturitionRecord) {
        Result result = Result.ok();
        parturitionRecordService.save(result, parturitionRecord);
        return result;
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("animal:parturitionRecord:edit")
    public Result update(ParturitionRecordDO parturitionRecord) {
        Result result = Result.ok();
        parturitionRecordService.update(result, parturitionRecord);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("animal:parturitionRecord:remove")
    public Result remove(Integer id) {
        Result result = Result.ok();
        parturitionRecordService.remove(result, id);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("animal:parturitionRecord:batchRemove")
    public Result remove(@RequestParam("ids[]") Integer[] ids) {
        Result result = Result.ok();
        parturitionRecordService.batchRemove(result, ids);
        return result;
    }

}
